package com.vo;

public class ResultVO {
    // 响应的编码， 比如 200, 500, 1001, 1002, 1001= 用户未登录
    private Integer code;
    // 响应的消息，200 代表成功，1001= 用户未登录
    private String msg;
    // 响应的数据，如果没有数据，data = null
    private Object data;

    // 无参构造
    public ResultVO() {
    }

    // 带参构造
    public ResultVO(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    // 返回结果
    public static ResultVO success(Object data) {
        return success(200, "ok", data);
    }

    public static ResultVO success(String msg, Object data) {
        return success(200, msg, data);
    }

    public static ResultVO success(Integer code, String msg, Object data) {
        return new ResultVO(code, msg, data);
    }

    public static ResultVO fail(String msg, Object data) {
        return fail(500, msg, data);
    }

    public static  ResultVO fail(Integer code, String msg, Object data) {
        return new ResultVO(code, msg, data);
    }

    // getting / setting 方法
    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResultVO{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
